package com.ctshk.rpc.order.air.service.impl.app;

import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ctshk.common.constant.CurrencyRateExchangeConstant;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.*;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.req.pay.NotifyConsumeReq;
import com.ctshk.common.utils.Assert;
import com.ctshk.common.utils.EntityUtil;
import com.ctshk.rpc.air.dto.*;
import com.ctshk.rpc.air.req.AirFlightQueryReq;
import com.ctshk.rpc.air.req.AirProductSaleRecordAddReq;
import com.ctshk.rpc.air.service.*;
import com.ctshk.rpc.order.air.dto.AirOrderListDTO;
import com.ctshk.rpc.order.air.dto.app.OrderDetailDTO;
import com.ctshk.rpc.order.air.dto.app.OrderProductDTO;
import com.ctshk.rpc.order.air.dto.app.OrderTouristDataDTO;
import com.ctshk.rpc.order.air.entity.*;
import com.ctshk.rpc.order.air.manager.AirOrderManager;
import com.ctshk.rpc.order.air.mapper.*;
import com.ctshk.rpc.order.air.req.AirOrderCancelReq;
import com.ctshk.rpc.order.air.req.AirProductCostTaxationData;
import com.ctshk.rpc.order.air.req.app.AddOrderReq;
import com.ctshk.rpc.order.air.req.app.AppPayOrderReq;
import com.ctshk.rpc.order.air.req.orderDetail.AirOrderFlightData;
import com.ctshk.rpc.order.air.service.IAirOrderService;
import com.ctshk.rpc.order.air.service.app.IAirProductOrderService;
import com.ctshk.rpc.payment.enums.PayCurrency;
import com.ctshk.rpc.payment.enums.PayOrderStatus;
import com.ctshk.rpc.payment.enums.PaymentMethod;
import com.ctshk.rpc.payment.req.PayCommonReq;
import com.ctshk.rpc.payment.service.IPayService;
import com.ctshk.rpc.system.dto.MainDataCurrencyQueryDTO;
import com.ctshk.rpc.system.service.IMainDataCurrencyService;
import com.ctshk.rpc.user.service.IOrderEsService;
import com.google.common.collect.Lists;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @BelongsProject: ctshk-cloud
 * @BelongsPackage: com.ctshk.rpc.order.air.service.impl.app
 * @Author: hef
 * @CreateTime: 2021-05-20 14:42
 * @Description: 描述
 */
@DubboService
public class AirProductOrderServiceImpl implements IAirProductOrderService {
    @DubboReference
    private IAirProductChannelOnlineSelfPlatformService iAirProductChannelOnlineSelfPlatformService;
    @Resource
    private IAirProductCostTouristService airProductCostTouristService;
    @DubboReference
    private IAirProductSaleRecordService iAirProductSaleRecordService;
    @DubboReference
    private IAirProductCostService iAirProductCostService;
    @DubboReference
    private IAirProductReservationSettingsService iAirProductReservationSettingsService;
    @Resource
    private AirOrderMapper airOrderMapper;

    @Resource
    private AirOrderUrgentMapper airOrderUrgentMapper;

    @DubboReference
    private IAirProductService iAirProductService;
    @DubboReference
    private IAirFlightService iAirFlightService;
    @Resource
    private AirOrderTouristMapper airOrderTouristMapper;
    @Resource
    private AirOrderFlightMapper airOrderFlightMapper;
    @DubboReference
    private IPayService iAirService;
    @Resource
    private AirOrderCollectionMapper airOrderCollectionMapper;
    @Resource
    private IAirOrderService iAirOrderService;
    @Resource
    private AirOrderRefundMapper airOrderRefundMapper;
    @DubboReference
    private IMainDataCurrencyService mainDataCurrencyService;
    @DubboReference
    private IOrderEsService orderEsService;


    @Override
    @Transactional(rollbackFor = Exception.class)
    public Long addOrder(AddOrderReq req, TokenUser currentUser) {
        Long userId = currentUser != null ? currentUser.getId() : null;
        String userName = currentUser != null ? currentUser.getUsername() : null;
        AtomicReference<BigDecimal> totalAmt = new AtomicReference<BigDecimal>(BigDecimal.ZERO);
        AtomicReference<BigDecimal> totalServiceAmt = new AtomicReference<BigDecimal>(BigDecimal.ZERO);
        List<AirOrderFlight> airOrderFlightList = Lists.newArrayList();
        //验证价格
        req.getOrderProductList().stream().forEach(product -> {
            //获取机票信息
            AirProductInfoDTO productInfo = iAirProductService.getById(product.getProductId());
            Assert.nonNull(productInfo, SystemError.AIR_PRODUCT_12004);
            //获取航班信息
            AirFlightDataDto flight = iAirFlightService.query(new AirFlightQueryReq(productInfo.getRouteId())).getData();
            Assert.nonNull(flight, SystemError.AIR_PRODUCT_12023);
            //获取乘坐日加幅
            AirProductChannelOnlineSelfPlatformDTO currentlyValidStrategy =
                    iAirProductChannelOnlineSelfPlatformService.getCurrentlyValidData(product.getProductId(), product.getDate(), req.getChannelId());

            Assert.nonNull(currentlyValidStrategy, SystemError.AIR_PRODUCT_12026);
            //获取成本
            List<AirProductCostTouristDTO> currentlyValidCost = airProductCostTouristService.getCurrentlyValidData(product.getProductId(), product.getDate());
            Map<Long, AirProductCostTouristDTO> touristMap = currentlyValidCost.stream()
                    .collect(Collectors.toMap(AirProductCostTouristDTO::getTouristTypeId, Function.identity()));
            //服务费
            AirProductReservationSettingsDTO data =
                    iAirProductReservationSettingsService.getByProductId(product.getProductId()).getData();
            Assert.nonNull(data, SystemError.AIR_PRODUCT_12028);
            //计算价格
            product.getOrderFlightPriceDataList().stream().forEach(tourist -> {
                //获取旅客类型对应成本
                AirProductCostTouristDTO touristCost = touristMap.get(Long.valueOf(tourist.getTouristTypeId()));
                Assert.nonNull(touristCost, SystemError.AIR_PRODUCT_12027, tourist.getTouristTypeName());
                //计算加幅
                BigDecimal costPrice = touristCost.getCostPrice();
                costPrice = currentlyValidStrategy.calculateIncreasePrice(costPrice);
                Assert.isTrue(costPrice.compareTo(tourist.getPrice()) == 0, SystemError.AIR_ORDER_15030);
                //校验税费
                BigDecimal taxAmt = tourist.getAirProductCostTaxationDTOList().stream()
                        .map(AirProductCostTaxationData::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal checkAmt = touristCost.getAirProductCostTaxationDTOList()
                        .stream().map(AirProductCostTaxationDTO::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                Assert.isTrue(taxAmt.compareTo(checkAmt) == 0, SystemError.AIR_ORDER_15030);
                BigDecimal serviceAmt;
                if (NumberConstant.TWO.getValue().equals(data.getServiceChargeType())) {
                    serviceAmt = costPrice.multiply(data.getServiceChargePrice().divide(BigDecimal.valueOf(100)));
                } else {
                    serviceAmt = data.getServiceChargePrice();
                }
                totalServiceAmt.set(totalServiceAmt.get().add(serviceAmt));
                costPrice = costPrice.add(Optional.ofNullable(serviceAmt).orElse(BigDecimal.ZERO));
                BigDecimal unitPrice = costPrice.add(checkAmt);
                //获取该类型的旅客数量
                long count = req.getTouristList().stream().filter(item -> item.getTouristType().equals(tourist.getTouristTypeId())).count();
                totalAmt.set(totalAmt.get().add(unitPrice.multiply(BigDecimal.valueOf(count))));
            });
            //获取售卖记录
            List<AirProductSaleRecordDTO> salesRecord = iAirProductSaleRecordService.getByProductId(product.getProductId(), product.getDate());
            //校验成本可售数量
            Integer dailyStock = iAirProductCostService.getDailyStock(product.getProductId(), product.getDate());
            int soldNumber = salesRecord.stream().mapToInt(AirProductSaleRecordDTO::getSoldNumber).sum();
            soldNumber = soldNumber + req.getTouristList().size();
            Assert.isTrue(dailyStock.compareTo(Integer.valueOf(soldNumber)) >= 0, SystemError.AIR_ORDER_15009);
            //线上自营策略如果限购
            if (NumberConstant.ONE.getValue().equals(currentlyValidStrategy.getIsLimit())) {
                //官方渠道已售卖数量
                int sold = salesRecord.stream().filter(record -> Channel.PLATFORM.getCode().equals(record.getChannel()))
                        .mapToInt(AirProductSaleRecordDTO::getSoldNumber).sum();
                sold = sold + req.getTouristList().size();
                Assert.isTrue(currentlyValidStrategy.getLimitNum().compareTo(Integer.valueOf(sold)) >= 0, SystemError.AIR_ORDER_15009);
            }
            AirOrderFlight airOrderFlight = new AirOrderFlight();
            airOrderFlight.setFlightId(flight.getId());
            airOrderFlight.setProductId(productInfo.getId());
            airOrderFlight.setProductType(productInfo.getSource());
            airOrderFlight.setDate(product.getDate());
            airOrderFlight.setNumber(req.getTouristList().size() * req.getOrderProductList().size());
            airOrderFlight.setCompanyId(flight.getCompanyId());
            airOrderFlight.setCompanyName(flight.getCompanyName());
            airOrderFlight.setTripRank(product.getTripRank());
            airOrderFlight.setFlightNumber(flight.getFlightNumber());
            airOrderFlight.setCabinClass(productInfo.getCabinClass());
            airOrderFlight.setCabinName(productInfo.getCabinName());
            airOrderFlight.setDepTime(flight.getDepTime());
            airOrderFlight.setDepCityId(flight.getDepCityId());
            airOrderFlight.setDepCityName(flight.getDepCityName());
            airOrderFlight.setArrCityId(flight.getArrCityId());
            airOrderFlight.setArrCityName(flight.getArrCityName());
            airOrderFlight.setDepAirportId(flight.getDepAirportId());
            airOrderFlight.setDepAirportName(flight.getDepAirportName());
            airOrderFlight.setArrAirportId(flight.getArrAirportId());
            airOrderFlight.setArrAirportName(flight.getArrAirportName());
            airOrderFlight.setArrTime(flight.getArrTime());
            Duration between = Duration.between(flight.getArrTime(), flight.getDepTime());
            long minuteInterval = Math.abs(between.toMinutes());
            airOrderFlight.setTimeConsuming(minuteInterval / 60 + "时" + minuteInterval % 60 + "分");
            airOrderFlight.setFlightPrice(JSONArray.toJSONString(product.getOrderFlightPriceDataList()));
            //组装航班信息
            airOrderFlightList.add(airOrderFlight);
        });
        Assert.isTrue(totalAmt.get().compareTo(req.getTotalAmount()) == 0, SystemError.AIR_ORDER_15030);
        //插入订单信息
        Long airOrderId = IdWorker.getId();
        LocalDateTime createTime = LocalDateTime.now();
        AirOrder airOrder = EntityUtil.copy(req, AirOrder.class); //修改了传入参数的封装，修改获取参数的对象
        //AirOrder airOrder = EntityUtil.copy(req.getAppContactReq(), AirOrder.class);
        airOrder.setTripType(req.getTripType());
        airOrder.setContactName(airOrder.getSurname() + airOrder.getName());
        airOrder.setId(airOrderId);
        airOrder.setCreateId(userId);
        airOrder.setGmtCreate(createTime);
        airOrder.setModifiedId(userId);
        airOrder.setGmtModified(createTime);
        airOrder.setUserId(req.getUserId());
        airOrder.setIsDeleted(IsDeletedCode.NO.getCode());
        airOrder.setOrderAmount(totalAmt.get());
        airOrder.setReceivableAmount(totalAmt.get());
        //后面设置服务费
        airOrder.setServiceFee(totalServiceAmt.get());
        airOrder.setSalesMethods(1);
        airOrder.setOrderNumber(AirOrderManager.getOrderNumer(null, null));
        airOrder.setPaymentStatus(OrderPaymentStatus.UN_PAYMENT.getCode());
        airOrder.setCancelStatus(null);
        airOrder.setOrderStatus(OrderStatus.UN_PAYMENT.getCode());
        airOrder.setScheduledStatus(OrderScheduledStatus.CONFIRM_RESERVE.getCode());
        airOrder.setSource(OrderSource.H5.getCode());
        /**最晚付款时间为创建订单后15分钟*/
        airOrder.setPayExpireDate(createTime.plusMinutes(15));
        airOrderMapper.insert(airOrder);

        /*//获取紧急联系人信息
        AirOrderUrgent airOrderUrgent = EntityUtil.copy(req.getAppUrgentContactReq(), AirOrderUrgent.class);
        airOrderUrgent.setId(airOrderId);
        //插入紧急联系人信息
        airOrderUrgentMapper.insert(airOrderUrgent);*/

        //插入旅客信息
        req.getTouristList().stream()
                .map(airOrderTouristData -> EntityUtil.copy(airOrderTouristData, AirOrderTourist.class))
                .forEach(airOrderTourist -> {
                    airOrderTourist.setId(IdWorker.getId());
                    airOrderTourist.setOrderId(airOrderId);
                    airOrderTourist.setCreateId(userId);
                    airOrderTourist.setGmtCreate(createTime);
                    airOrderTourist.setModifiedId(userId);
                    airOrderTourist.setGmtModified(createTime);
                    airOrderTourist.setIsDeleted(IsDeletedCode.NO.getCode());
                    airOrderTourist.setTouristName(airOrderTourist.getSurname() + airOrderTourist.getName());
                    airOrderTouristMapper.insert(airOrderTourist);
                });
        /**航班信息*/
        //锁库存(创建售卖记录)
        airOrderFlightList.parallelStream().forEach(airOrderFlight -> {
            airOrderFlight.setId(IdWorker.getId());
            airOrderFlight.setOrderId(airOrderId);
            airOrderFlight.setCreateId(userId);
            airOrderFlight.setModifiedId(userId);
            airOrderFlight.setIsDeleted(0);
            airOrderFlight.setGmtCreate(LocalDateTime.now());
            airOrderFlight.setGmtModified(LocalDateTime.now());
            airOrderFlightMapper.insert(airOrderFlight);
            AirProductSaleRecordAddReq airProductSaleRecordAddReq = new AirProductSaleRecordAddReq();
            airProductSaleRecordAddReq.setChannel(2);
            airProductSaleRecordAddReq.setCustomId(userId);
            airProductSaleRecordAddReq.setCustomName(userName);
            airProductSaleRecordAddReq.setOrderId(airOrderFlight.getOrderId());
            airProductSaleRecordAddReq.setProductId(airOrderFlight.getProductId());
            airProductSaleRecordAddReq.setSalesDate(airOrderFlight.getDate());
            airProductSaleRecordAddReq.setSoldNumber(req.getTouristList().size());
            iAirProductSaleRecordService.add(airProductSaleRecordAddReq, userId);
        });
        sendOrderToAppUser(airOrderId);
        return airOrderId;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Object payOrder(AppPayOrderReq req, TokenUser currentUser) {
        //获取订单详情
        AirOrder airOrder = airOrderMapper.selectById(req.getOrderId());
        Assert.nonNull(airOrder, SystemError.AIR_ORDER_15016);
        Assert.isTrue(
                OrderPaymentStatus.UN_PAYMENT.getCode().equals(airOrder.getPaymentStatus()) &&
                        OrderStatus.UN_PAYMENT.getCode().equals(airOrder.getOrderStatus())
                , SystemError.AIR_ORDER_15031);
        PayCommonReq payCommonReq = new PayCommonReq();
        //payCommonReq.setOrderNumber(airOrder.getOrderNumber());
        payCommonReq.setSubject("机票预订");
        payCommonReq.setBody("订购机票");
        payCommonReq.setTotalFee(airOrder.getOrderAmount());
        payCommonReq.setCurrency(PayCurrency.HKD);
        payCommonReq.setPaymentMethod(PaymentMethod.getByPayRefundMethodId(req.getPaymentMethodId()));
        payCommonReq.setNotifyUrl(req.getCallBackUrl());
        payCommonReq.setOrderValidTime(airOrder.getPayExpireDate());
        Result pay = iAirService.pay(payCommonReq, currentUser != null ? currentUser.getId() : null);
        Assert.isTrue(pay.isSuccess(), SystemError.getDefined(pay.getCode()));
        updateStatusToAppUser(req.getOrderId());
        return pay.getData();
    }

    @Override
    public boolean payCallback(NotifyConsumeReq req) {
        //获取对应订单
        AirOrder airOrder = airOrderMapper.selectOne(Wrappers.<AirOrder>lambdaQuery().eq(AirOrder::getOrderNumber, req.getOrderNumber()));
        Assert.nonNull(airOrder, SystemError.AIR_ORDER_15016);
        //修改订单状态
        PayOrderStatus status = PayOrderStatus.getByStatus(req.getOrderStatus());
        //支付成功
        if (PayOrderStatus.FULFIL.equals(status)) {
            AirOrder update = new AirOrder();
            update.setId(airOrder.getId());
            //支付状态
            update.setPaymentStatus(OrderPaymentStatus.ALREADY_PAYMENT.getCode());
            //订单状态 ---待预订
            update.setOrderStatus(OrderStatus.CONFIRM_RESERVE.getCode());
            //更新时间
            update.setGmtModified(LocalDateTime.now());
            airOrderMapper.updateById(update);
            //新增收款记录
            PaymentMethod method = PaymentMethod.getByCode(req.getPaymentMethod());
            AirOrderCollection airOrderCollection = new AirOrderCollection();
            airOrderCollection.setCollectionNumber(AirOrderManager.getCollectionNumber());
            airOrderCollection.setId(IdWorker.getId());
            airOrderCollection.setOrderId(airOrder.getId());
            airOrderCollection.setGmtCreate(LocalDateTime.now());
            airOrderCollection.setGmtModified(LocalDateTime.now());
            airOrderCollection.setIsDeleted(IsDeletedCode.NO.getCode());
            airOrderCollection.setCollectionAmount(airOrder.getOrderAmount());
            airOrderCollection.setCollectionWayId(method.getPayRefundMethodId());
            airOrderCollection.setCollectionWay(method.getName());
            airOrderCollection.setPayer(req.getPaymentAccount());
            airOrderCollection.setRemark(airOrder.getRemark());
            airOrderCollection.setStatus(0);
            airOrderCollectionMapper.insert(airOrderCollection);
            updateStatusToAppUser(airOrder.getId());
        }
        return true;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean cancelOrder(AirOrderCancelReq req, TokenUser currentUser) {
        Long userId = currentUser != null ? currentUser.getId() : null;
        //获取订单
        AirOrder airOrder = airOrderMapper.selectById(req.getId());
        Assert.nonNull(airOrder, SystemError.AIR_ORDER_15016);
        //没有取消过 或者 审批不通过才能再次申请
        Assert.isTrue(airOrder.getCancelStatus() == null
                        || OrderCancelStatus.APPROVAL_FAIL.getCode().equals(airOrder.getCancelStatus()),
                SystemError.AIR_ORDER_15032);
        //未支付的调用之前B端的接口
        if (OrderPaymentStatus.UN_PAYMENT.getCode().equals(airOrder.getPaymentStatus())) {
            Result result = iAirOrderService.cancelOrder(req, currentUser);
            Assert.isTrue(result.isSuccess(), SystemError.getDefined(result.getCode()));
            return true;
        }
        //已付款 ...
        /******************TODO 发起退款审批**/
        //TODO
        /******************修改订单状态**/
        AirOrder update = new AirOrder();
        update.setId(airOrder.getId());
        update.setGmtModified(LocalDateTime.now());
        update.setCancelStatus(OrderCancelStatus.UNDER_APPROVAL.getCode());
//        update.setRefundApprovalId()
        airOrderMapper.updateById(update);
        /******************插入退款记录**/
        AirOrderRefund refund = new AirOrderRefund();
        refund.setOrderId(airOrder.getId());
        refund.setRefundNumber(AirOrderManager.getRefundNumber());
        refund.setRefundAmount(airOrder.getOrderAmount());
//        refund.setRefundWayId();
//        refund.setRefundWay();
//        refund.setRefundAccount();
        refund.setRefundReason(req.getRefundReason());
        MainDataCurrencyQueryDTO currencyEntity = mainDataCurrencyService.getExchangeCurrencyEntity("HKD", CurrencyRateExchangeConstant.MARKET_EXCHANGE_RATE_);
        if (currencyEntity != null) {
            refund.setCurrencyId(currencyEntity.getId());
            refund.setCurrency(currencyEntity.getCurrencyName());
            refund.setExchangeRateId(currencyEntity.getId());
            refund.setExchangeRate(BigDecimal.ONE);
            refund.setExchangeRateAfterMoney(airOrder.getOrderAmount());
        }
        refund.setRemark(req.getRemark());
        refund.setStatus(OrderRefundStatus.AUDITING.getCode());
        refund.setCreateId(userId);
        refund.setModifiedId(userId);
        refund.setIsDeleted(IsDeletedCode.NO.getCode());
        refund.setId(IdWorker.getId());
        refund.setGmtCreate(LocalDateTime.now());
        refund.setGmtModified(LocalDateTime.now());
        airOrderRefundMapper.insert(refund);
        updateStatusToAppUser(req.getId());
        return true;
    }

    @Override
    public OrderDetailDTO getOrderDetail(Long orderId) {
        AirOrder airOrder = airOrderMapper.selectById(orderId);
        Assert.nonNull(airOrder, SystemError.AIR_ORDER_15016);
        OrderDetailDTO dto = EntityUtil.copy(airOrder, OrderDetailDTO.class);
        //获取航班信息
        List<AirOrderFlight> flights = airOrderFlightMapper.selectList(Wrappers.
                <AirOrderFlight>lambdaQuery().eq(AirOrderFlight::getOrderId, airOrder.getId()));
        List<OrderProductDTO> products = Lists.newArrayList();
        flights.stream().forEach(item -> {
            OrderProductDTO product = EntityUtil.copy(item, OrderProductDTO.class);
            AirProductReservationSettingsDTO data = iAirProductReservationSettingsService.getByProductId(item.getProductId()).getData();
            if (data != null) {
                product.setBookingInformation(data.getBookingInformation());
                product.setBaggageStates(data.getBaggageStates());
            }
            products.add(product);
        });
        dto.setProductList(products);
        //获取旅客信息
        List<AirOrderTourist> touristList = airOrderTouristMapper.selectList(Wrappers.
                <AirOrderTourist>lambdaQuery().eq(AirOrderTourist::getOrderId, airOrder.getId()));
        List<OrderTouristDataDTO> tourists = EntityUtil.copyList(touristList, OrderTouristDataDTO.class);
        dto.setTouristList(tourists);
        return dto;
    }

    public AirOrderListDTO buildEsOrderDTO(Long orderId) {
        AirOrder airOrder = airOrderMapper.selectById(orderId);
        AirOrderListDTO orderDTO = EntityUtil.copy(airOrder, AirOrderListDTO.class);
        List<AirOrderFlight> airOrderFlights = airOrderFlightMapper.selectList(Wrappers.<AirOrderFlight>lambdaQuery()
                .eq(AirOrderFlight::getOrderId,orderId));
        orderDTO.setAirOrderFlightDataList(EntityUtil.copyList(airOrderFlights, AirOrderFlightData.class));
        return orderDTO;
    }

    /**
     * 异步发送订单数据到个人中心
     * @param orderId 订单Id
     */
    public void sendOrderToAppUser(Long orderId) {
        CompletableFuture.runAsync(() -> {
            try {
                AirOrderListDTO orderDTO = buildEsOrderDTO(orderId);
                orderEsService.saveOrderToEs(orderDTO,SystemBusinessType.AIR_TICKET);
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
    }

    /**
     * 异步更新订单状态到个人中心
     */
    public void updateStatusToAppUser(Long orderId) {
        CompletableFuture.runAsync(() -> {
            try {
                AirOrder order = airOrderMapper.selectById(orderId);
                orderEsService.updateStatusToEs(order.getId(),SystemBusinessType.AIR_TICKET.getCode(),
                        order.getOrderStatus(), order.getPaymentStatus(), order.getScheduledStatus(),
                        order.getCancelStatus());
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
    }
}
